Code cleanup, improved testo case, and leak fixes from Olaf Klein.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 6 May 2005 17:08:52 +0000 (17:08 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 6 May 2005 17:08:52 +0000 (17:08 +0000)
gpsbabel/Makefile
gpsbabel/tef_xml.c
gpsbabel/testo

index e08ef553c25df1ac4c5e7a34200fc2ad87d674d0..1decd68fabdfaa1976bcf96b82ae102c3b68c2e0 100644 (file)
@@ -3,7 +3,7 @@
 # type that is XML-ish (i.e. gpx or geocaching.com's/loc) you can uncomment
 # INHIBIT_EXPAT and coment out LIBEXPAT on just to get a build working quickly.
 # INHIBIT_EXPAT=-DNO_EXPAT
-LIBEXPAT=-lexpat #-lefence
+LIBEXPAT=-lexpat -lefence
 
 # USB may required non-standard libraries (like libusb) be installed
 # and may not be available on all OSes.  Uncomment this to remove the key
index 51946ad26c0fb686a4a7f6d8eff173e02ba2dc88..b53b4cc3a16a66e2a8e7a918317e4fed3cc8afb9 100644 (file)
@@ -30,20 +30,16 @@ static char *deficon = NULL;
 
 static waypoint *wpt_tmp = NULL;
 static int wpt_tmp_valid = 0;
-static route_head *track = NULL;
+static int item_count = -1;
 static int waypoints = 0;
 
+static route_head *route = NULL;
+
 FILE *fd;
 FILE *ofd;
 
 #define MYNAME "TourExchangeFormat"
 
-// void DBG(const char *func)
-// {
-//     printf("DBG(%s)=in %s\n", MYNAME, func);
-// }
-
-
 #if NO_EXPAT
 void
 tef_xml_rd_init(const char *fname)
@@ -58,14 +54,14 @@ tef_xml_read(void)
 
 #else
 
-static xg_callback     tef_start, tef_item_end, tef_list_start, tef_header, tef_list_end;
-static xg_callback     tef_item_start, tef_point;
+static xg_callback     tef_start, tef_header, tef_list_start, tef_list_end;
+static xg_callback     tef_item_start, tef_point, tef_item_end;
 
 static 
 xg_tag_mapping tef_xml_map[] = {
        { tef_start,            cb_start,       "/TEF" },
        { tef_header,           cb_start,       "/TEF/Header" },
-       { tef_list_start,       cb_start,       "/TEF/WaypointList" },
+       { tef_list_start,       cb_start,       "/TEF/WaypointList" },
        { tef_item_start,       cb_start,       "/TEF/WaypointList/Item" },
        { tef_point,            cb_start,       "/TEF/WaypointList/Item/Point" },
        { tef_item_end,         cb_end,         "/TEF/WaypointList/Item" },
@@ -105,42 +101,40 @@ void
 tef_header(const char *args, const char **attrv)
 {
        const char **avp = &attrv[0];
-       char buff[1024];
-
-       track = route_head_alloc();
-
-        while (*avp) {
-                if (strcmp(avp[0], "Name") == 0) 
-               {
-                       track->rte_name = xstrdup(str_utf8_to_cp1252(avp[1]));
-                }
-                else if (strcmp(avp[0], "Software") == 0) 
-               {
-                       track->rte_desc = xstrdup(str_utf8_to_cp1252(avp[1]));
-                }
-                avp+=2;
-        }
-       
-       if (!track->rte_name) track->rte_name = xstrdup("No name");
-       if (!track->rte_desc) track->rte_desc = xstrdup("No description");
 
-       route_add_head(track);
+       route = route_head_alloc();
+        while (*avp) 
+       {
+           if (strcmp(avp[0], "Name") == 0) 
+           {
+               route->rte_name = str_utf8_to_cp1252(avp[1]);
+           }
+           else if (strcmp(avp[0], "Software") == 0) 
+           {
+               route->rte_desc = str_utf8_to_cp1252(avp[1]);
+           }
+            avp+=2;
+        }
+       route_add_head(route);
 }
 
-
 /*
- * tef_list_start: 
+ *
  */
-
-void 
-tef_list_start(const char *args, const char **unused)
+void
+tef_list_start(const char *args, const char **attrv)
 {
-       if (!track)
+       const char **avp = &attrv[0];
+
+        while (*avp) 
        {
-           track = route_head_alloc();
-           track->rte_name = xstrdup("Unknown");
-           route_add_head(track);
-       }
+           if (strcmp(avp[0], "ItemCount") == 0) 
+           {
+               sscanf(avp[1], "%d", &item_count);
+           }
+            avp+=2;
+        }
 }
 
 /*
@@ -154,21 +148,24 @@ void waypoint_final(int force)
        if (force || wpt_tmp_valid > 0)
        {
            waypt_add(wpt_tmp);
-           if (track)
+           if (route)
            {
                waypoint *wpt = waypt_new();
                wpt->shortname = xstrdup(wpt_tmp->shortname);
                wpt->description = xstrdup(wpt_tmp->description);
-               wpt->creation_time = wpt_tmp->creation_time;
                wpt->latitude = wpt_tmp->latitude;
                wpt->longitude = wpt_tmp->longitude;
-               route_add_wpt(track, wpt);
+               route_add_wpt(route, wpt);
                wpt_tmp = NULL;
            }
        }
+       else
+       {
+           waypt_free(wpt_tmp);
+           wpt_tmp = NULL;
+       }
 }
 
-
 /*
  * 
  */
@@ -188,7 +185,10 @@ void
 tef_list_end(const char *args, const char **unused)
 {
        waypoint_final(1);
-       waypoints++;
+       if (waypoints != item_count)
+       {
+           fatal(MYNAME ": count waypoints differ to interlal ItemCount!\n");
+       }
 }
 
 /*
@@ -199,23 +199,19 @@ void
 tef_item_start(const char *args, const char **attrv)
 {
        const char **avp = &attrv[0];
-       const char buf[1024];
 
        wpt_tmp = waypt_new();
        wpt_tmp_valid = 0;
-       wpt_tmp->creation_time = current_time();
        
        while (*avp) 
        {
            if (0 == strcmp(avp[0], "PointDescription")) 
            {
-//             sprintf(buf, "%04i-%s", waypoints, str_utf8_to_cp1252(avp[1]));
-               sprintf(buf, "%s", str_utf8_to_cp1252(avp[1]));
-               wpt_tmp->shortname = xstrdup(buf);
+               wpt_tmp->shortname = str_utf8_to_cp1252(avp[1]);
            }
            if (0 == strcmp(avp[0], "SegDescription")) 
            {
-               wpt_tmp->description = xstrdup(str_utf8_to_cp1252(avp[1]));
+               wpt_tmp->description = str_utf8_to_cp1252(avp[1]);
            }
            if ((0 == strcmp(avp[0], "ViaStation")) && (0 == strcmp(avp[1], "true")))
            {
@@ -236,20 +232,21 @@ tef_point(const char *args, const char **attrv)
        
         const char **avp = &attrv[0];
        char *comma;
-        while (*avp) {
-                if (strcmp(avp[0], "y") == 0) 
-               {
-                       comma = strstr(avp[1], ",");
-                       if (comma) *comma='.';
-                        sscanf(avp[1], "%lf", &wpt_tmp->latitude);
-                }
-                else if (strcmp(avp[0], "x") == 0) 
-               {
-                       comma = strstr(avp[1], ",");
-                       if (comma) *comma='.';
-                        sscanf(avp[1], "%lf", &wpt_tmp->longitude);
-                }
-                avp+=2;
+        while (*avp) 
+       {
+           if (strcmp(avp[0], "y") == 0) 
+           {
+               comma = strstr(avp[1], ",");
+               if (comma) *comma='.';
+                sscanf(avp[1], "%lf", &wpt_tmp->latitude);
+           }
+           else if (strcmp(avp[0], "x") == 0) 
+           {
+               comma = strstr(avp[1], ",");
+               if (comma) *comma='.';
+               sscanf(avp[1], "%lf", &wpt_tmp->longitude);
+           }
+            avp+=2;
         }
 }
 
@@ -287,7 +284,7 @@ tef_xml_rd_deinit(void)
 
 ff_vecs_t tef_xml_vecs = {
        ff_type_file,
-       { ff_cap_none, ff_cap_none, ff_cap_write },
+       { ff_cap_none, ff_cap_none, ff_cap_read },
        tef_xml_rd_init,        
        NULL,   
        tef_xml_rd_deinit,
index a82785796db84cbc40aabd84715ee2ea6a02d970..06b36fe9f40abb024231f36bbae674f40b08846f 100755 (executable)
@@ -686,13 +686,12 @@ ${PNAME} -i geo -f geocaching.loc  -o geo -F ${TMPDIR}/geocustom.out
 # Write something to the various output-only formats
 #
 ${PNAME} -i geo -f geocaching.loc -o text -F ${TMPDIR}/text.out -o html -F ${TMPDIR}/html.out -o vcard -F ${TMPDIR}/vcard.out #-o palmdoc -F ${TMPDIR}/pd.out
-./gpsbabel -i tef -f tef_xml.sample.xml -o gpx -F /dev/null
-
 
 #
-# FIXME: do a 'real' test here.
+# TourExchangeFormat tef (read only)
 #
-
-${PNAME} -i tef -f reference/track/tef_xml.sample.xml -o gpx -F /dev/null
+rm -f ${TMPDIR}/tef_xms.mps
+${PNAME} -r -i tef -f reference/route/tef_xml.sample.xml -o mapsource -F ${TMPDIR}/tef_xml.mps
+bincompare ${TMPDIR}/tef_xml.mps reference/route/tef_xml.mps
 
 exit 0